using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Domain.Specifications
{
    /// <summary>
    /// Specifications for PredicateSpecification.
    /// </summary>
    [TestClass]
    public class WhenTestingSatisfactionOfPredicateSpecification
    {
        /// <summary>
        /// Is satisfied when the predicate returns true.
        /// </summary>
        [TestMethod]
        public void ShouldBeSatisfiedWhenPredicateReturnsTrue()
        {
            ISpecification<int> specification = new PredicateSpecification<int>(TruePredicate);
            Assert.IsTrue(specification.IsSatisfiedBy(0));
        }

        /// <summary>
        /// Is not satisfied when the predicate returns false.
        /// </summary>
        [TestMethod]
        public void ShouldNotBeSatisfiedWhenPredicateReturnsFalse()
        {
            ISpecification<int> specification = new PredicateSpecification<int>(FalsePredicate);
            Assert.IsFalse(specification.IsSatisfiedBy(0));
        }

        /// <summary>
        /// Returns true.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <returns></returns>
        private static bool TruePredicate<T>(T item)
        {
            return true;
        }

        /// <summary>
        /// Returns false.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <returns></returns>
        private static bool FalsePredicate<T>(T item)
        {
            return false;
        }
    }
}